package com.atguigu.chaptar1

object Test11 {
  /**
   * 1、对数组中的每个元素进行操作,操作规则由外部决定
   * Array("spark","hello","java","hadoop")
   * 规则: 获取每个元素的长度 [不确定]
   * 结果: Array(5,5,4,6)
   */
  def main(args: Array[String]): Unit = {
    val arr = Array("spark","hello","java","hadoop")
    val len=(x:String)=>x.length
    println(getLength(arr, len).toList)
    println(getLength(arr, _.length).toList)
  }
  def getLength(arr:Array[String],func:(String)=>Int)=for (i<-arr) yield func(i)


}
